package com.flink.api.unit4;

import com.flink.pojo.WaterSensor;
import org.apache.flink.api.common.functions.FilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * map_1
 *
 * @author caizhiyang
 * @since 2024-02-21
 */
public class filter_1 {

    /**
     * filter算子
     * @param args
     */
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<WaterSensor> source = env.fromElements(
                new WaterSensor("sensor_1", 1L, 1),
                new WaterSensor("sensor_1", 11L, 1),
                new WaterSensor("sensor_2", 2L, 2),
                new WaterSensor("sensor_2", 12L, 2)
        );

        SingleOutputStreamOperator<WaterSensor> singleOutputStreamOperator = source.filter((FilterFunction<WaterSensor>) waterSensor -> {
            return waterSensor.getId().equals("sensor_1");
        });

        singleOutputStreamOperator.print();

        env.execute();
    }
}
